<?php
class Weixin extends MY_M_Controller
{
	public $appId = 'wx801107e527a0c57e';
	public $appSecret = 'b286b528ca1b75591f9fe57f8961d11d';
	
    /**
     * 微信公众号登录
     */
    public function login()
    {
    	$code = $this->input->get_post('code');
		
		if($code){

			$url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.config_item('wx_appid').'&secret='.config_item('wx_app_secret').'&code='.$code.'&grant_type=authorization_code';
			$c = file_get_contents($url);
			$r = json_decode($c, true);
			
			$_SESSION['user']['openid'] = $r['openid'];
			header('Location:'.$_SESSION['redirect_uri']);
		}
    }
}